package cn.mango.app;

import cn.mango.app.ui.MainActivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;

public class AppStart extends Activity {
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		// 设置启动界面所需的布局
		final View view = View.inflate(getApplicationContext(), R.layout.start,
				null);
		setContentView(view);
		
		// 为启动界面设置透明度渐变动画，从30%到100%
		// 持续时间为2秒
		AlphaAnimation animation = new AlphaAnimation(0.3F, 1.0F);
		animation.setDuration(2000L);
		animation.setAnimationListener(new AnimationListener() {
			@Override
			public void onAnimationStart(Animation animation) {}
			@Override
			public void onAnimationRepeat(Animation animation) {}
			@Override
			public void onAnimationEnd(Animation animation) {
				//动画结束时跳转到主页
				redirectTo();
			}
		});
		view.startAnimation(animation);
	}
	
	/**
	 * 重定向到主界面
	 */
	private void redirectTo() {
		Intent intent = new Intent(this,MainActivity.class);
		startActivity(intent);
		finish();
	}
}
